<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    // 构造函数
    function Axios(config){
        // 初始化
        this.default = config
        this.interceptors = {
            request: {},
            response: {}
        }
    }
    Axios.prototype.request = function (config){
        console.log('request',config)
    }
    Axios.prototype.get = function (config){
        config.method = 'GET'
        this.request(config)
    }
    Axios.prototype.post = function (config){
        config.method = 'POST'
        this.request(config)
    }
    function createInstance(config){
        let context = new Axios(config)

        let instance = Axios.prototype.request.bind(context) //可以使用instance()

        for (let prototypeKey in Axios.prototype) {

            instance[prototypeKey] = Axios.prototype[prototypeKey] // 可以使用instance.get()等
        }
        for (let contextKey in context) {
            instance[contextKey] = context[contextKey]
        }

        return instance
    }
    let instance = createInstance();
    console.dir(instance)
    instance.get({method:'1'})
    console.dir(instance)
    instance({
        method:'post'
    })
    console.dir(instance)

</script>
</body>
</html>